// import User from '../models/user.model'
// import extend from 'lodash/extend'
import errorHandler from '../helpers/dbErrorHandler'
import {sendText} from '../kam_op/send.msg'

const robot_wxid = "wxid_dyj8lg3du5lj22"

const notice = async (req, res) => {
  console.log("req.body: " , req.body)
  const event = req.body['event']
  const to_wxid = req.body['to_wxid']
  const msg = req.body['msg']

  
  try {
    if(event == "SendOutMsg" && msg.indexOf("测试") != -1) {
      sendText({
        "robot_wxid": robot_wxid,
        "to_wxid": to_wxid,
        "msg": "hello I'm Node Js"
      })
    }
    return res.status(200).json({
      status: "ok"
    })
  } catch (err) {
    const message = errorHandler.getErrorMessage(err)
    console.error("message:"+err.message)
    return res.status(400).json({
      error: message
    })
  }
}


export default {
  notice
}
